package com.nali.dal.statement.function;

import java.util.Map;

public class FunctionArgument {
	private Object value;
	private boolean isColumn;
	private FunctionArgument(Object value, boolean isColumn) {
		this.value = value;
		this.isColumn = isColumn;
	}
	
	public static FunctionArgument column(String name) {
		return new FunctionArgument(name, true);
	}
	
	public static FunctionArgument value(Object value) {
		return new FunctionArgument(value, false);
	}

	/**
	 * 是否字段
	 */
	public boolean isColumn() {
		return isColumn;
	}
	
	/**
	 * 是否常量
	 */
	public boolean isConstant() {
		return !isColumn;
	}
	
	/**
	 * 字段名
	 */
	public String getColumn() {
		if(isColumn) {
			return (String) value;
		} else {
			throw new FunctionException("is not a column");
		}
	}
	
	/**
	 * 常量
	 */
	public Object getConstant() {
		if(isColumn) {
			throw new FunctionException("is not a constant");
		} else {
			return value;
		}
	}
	
	public Object getValue(Map<String, Object> dataMap) {
		if(isColumn) {
			return dataMap.get(value);
		} else {
			return value;
		}
	}
}
